<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>用章照</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="100px" ref="editForm">
          <el-form-item label="上传用章照片:" prop="name">
            <el-upload
                class="addicon"
                accept="image/png, image/jpeg"
                list-type="picture-card"
                :action="$uploadImg"
                :file-list="fileList"
                :limit="1"
                :on-success="handleSuccess"
                :on-remove="handleRemove"
                :before-upload="beforeAvatarUpload">
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small" >返回</el-button>
        <el-button size="small" type="primary" @click.native="editSubmit">确认用章</el-button>
      </div>
    </div>
    <AuxiliaryModule @getInformation="getInformation" :typeData="typeData"></AuxiliaryModule>
  </div>
</template>

<script>

export default {
  props: ['visible','sealId'], // commoent 学生点评 collection 学生采集
  components: {
  },
  data() {
    return {
      typeData:'seal_return',
      dialogVisible: false,
      fileList: [],
      inopenLink:[]
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if(!this.visible){
        this.pic = '';
        this.fileList = [];
      }
    }
  },
  created() {
  },
  methods: {
    handleSuccess(response) {
      this.pic = response.data.name
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      if(this.pic){
        this.$message.error('最多一张图')
        return
      }
      return isLt2M
    },
    getDetail () {
      this.$fetch(this.api.licence.edit, {id: this.licenceId}).then((response) => {
        if (!response.code) {
          this.editForm.name = response.vo.name;
          this.editForm.user_id = response.vo.user?response.vo.user.id: '';
          this.examine_user = this.getJson(response.vo.user)
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    handleRemove(file, fileList) {
      this.pic = ''
    },
    // 提交数据
    async editSubmit () {
      // 验证信息
      // if(!this.pic){
      //   this.$message.error('选择图片上传')
      //   return
      // }
      let data = await this.$post(this.api.seal.seal_end, {end_file: this.pic, id: this.sealId});
      if (!data.code) {
        this.$message.success('操作成功！')
        this.closePOpup()
        this.$emit('InitFn')
      } else {
        this.$message.error(data.msg)
      }
    },
    // 同步数据
    getInformation(option) {
      for (let item of option) {
        if (item.type === 'img' && item.number === 1) {
          this.fileList = item.value
        }
      }
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}
.hearder-search{
  display: flex;
  align-items: center;
}
</style>


